package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.AdminOperation;
import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.dto.auditRisk.AuditRiskDTO;
import com.etone.smartAudit.service.AuditRiskService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.auditRisk.AuditRiskDetailVO;
import com.etone.smartAudit.vo.auditRisk.AuditRiskHistoryListVO;
import com.etone.smartAudit.vo.auditRisk.AuditRiskListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-06-17 18:10:15
 * @Description AuditRiskController
 */
@AllArgsConstructor
@RestController
@Api(tags = "审计风险", value = "AuditRiskController")
public class AuditRiskController {

    private AuditRiskService auditRiskService;

    @ApiOperation(value = "审计风险列表《完》")
    @GetMapping("/auditRisks")
    public PagerVO<AuditRiskListVO> list(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "关键字(审计疑点/内容摘要)") @RequestParam(required = false) String key,
            @ApiParam(value = "一级目录") @RequestParam(required = false) String level1,
            @ApiParam(value = "二级目录") @RequestParam(required = false) String level2,
            @ApiParam(value = "开始时间") @RequestParam(required = false) Date startUpdateTime,
            @ApiParam(value = "结束时间") @RequestParam(required = false) Date endUpdateTime
    ) {
        return auditRiskService.list(key, level1, level2, startUpdateTime, endUpdateTime, page, pageSize);
    }

    @ApiOperation(value = "审计风险历史记录列表《完》")
    @GetMapping("/auditRisks/{auditRiskId}/history")
    public PagerVO<AuditRiskHistoryListVO> listAuditRiskHistory(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "审计id", required = true) @PathVariable Integer auditRiskId
    ) {
        return auditRiskService.findAuditRiskHistoryList(auditRiskId, page, pageSize);
    }

    @ApiOperation(value = "审计风险详情《完》")
    @GetMapping("/auditRisks/{id}")
    public AuditRiskDetailVO detail(
            @ApiParam(value = "id", required = true) @PathVariable Integer id) {
        return auditRiskService.getAuditRiskDetailVO(id);
    }

    @AdminOperation(module = "风险点管控", item = "添加")
    @ApiOperation(value = "增加审计风险《完》")
    @PostMapping("/auditRisks")
    public void add(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "风险参数") @RequestBody @Validated AuditRiskDTO auditRiskDTO) {
        auditRiskService.save(null, auditRiskDTO, admin);
    }

    @AdminOperation(module = "风险点管控", item = "编辑")
    @ApiOperation(value = "编辑审计风险《完》")
    @PutMapping("/auditRisks/{id}")
    public void edit(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "id", required = true) @PathVariable Integer id,
            @ApiParam(value = "风险参数") @RequestBody @Validated AuditRiskDTO auditRiskDTO) {
        auditRiskService.save(id, auditRiskDTO, admin);
    }

    @ApiOperation(value = "删除风险审计《完》")
    @DeleteMapping("/auditRisks/{id}")
    @AdminOperation(module = "风险点管控", item = "删除")
    public void delete(
            @ApiParam(value = "id", required = true) @PathVariable Integer id,
            @ApiIgnore @LoginAdmin Admin loginAdmin
    ) {
        auditRiskService.delete(id, loginAdmin);
    }

    @ApiOperation(value = "批量删除风险审计《完》")
    @DeleteMapping("/auditRisks/batch/{ids}")
    @AdminOperation(module = "风险点管控", item = "批量删除")
    public void delete(
            @ApiParam(value = "ids") @PathVariable List<Integer> ids,
            @ApiIgnore @LoginAdmin Admin loginAdmin
    ) {
        auditRiskService.delete(ids, loginAdmin);
    }
}
